import React, { FC, useState, useEffect } from 'react'
// 碳排放
import $axios from '@/utils/axios'
import { Select,Radio } from 'antd'
import Dynamic from '@/api/dynamic'
const { Option } = Select
interface TableDefinedRadioProps {
    api_id: string;
    key_label:string;
    key_value:string;
    value: string;
    param: Object;
    onChange?: (arg0: unknown) => void;
}
const TableDefinedRadio: FC<TableDefinedRadioProps> = (props: TableDefinedRadioProps) => {
    const [list, setList] = useState([]);
    const {
        api_id,
        key_label = 'label',
        key_value = 'value',
        value = '',
        param = {},
        onChange = () => {},
    } = props
    const handerChange = (e) => {
        // console.log(val);
        onChange(e)
    }
    useEffect(() => {
        if(api_id){
            Dynamic.getDynamicQuery({
                apiID:api_id,
                'apiParam':param
              }).then((res) => {
                let data = res?.data?.data||[]
                setList(data);
            })
        }
        
    }, [])
    return <div>

        <Radio.Group value={value} onChange={handerChange}>
            {list.map((item) => (
            <Radio value={item[key_value]}>{item[key_label]}</Radio>
        ))}
        </Radio.Group>
    </div>
        
}

TableDefinedRadio.defaultProps = {
    "api_id": "",
    "key_label":"",
    "key_value":"",
    "value": "",
    "param":{},
}
export default TableDefinedRadio





